﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Reflection;
namespace BCL.Tool
{
    public enum ErrorCode
    {
        [Description("密码错误")]
        Success =0,

        [Description("密码错误")]
        Password = 1000,

        [Description("用户不存在")]
        UserName = 1001,

        [Description("用户名或密码错误")]
        NameOrPass = 1002,



        [Description("未知错误")]
        Unknown =65535
    }

    public static class ErrorCodeLogic
    {
        private static Type type;
        static ErrorCodeLogic()
        {
            type = typeof(ErrorCode);
        }
        public static string GetStr(this ErrorCode code)
        {
            MemberInfo[] memInfo = type.GetMember(code.ToString());
            if (null != memInfo && memInfo.Length > 0)
            {
                object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
                if (null != attrs && attrs.Length > 0)
                    return ((DescriptionAttribute)attrs[0]).Description;
            }
            return code.ToString();
        }
    }
}
